package com.cebbank.group.demoweb.controller;


import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/model/attr")
public class ModelAttrTestController {

    @ModelAttribute
    public void populateModel(@RequestParam(value = "abc") String abc, Model model){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("attr1", abc);
        model.addAllAttributes(modelMap);
    }

    @RequestMapping(value = "/hello")
    public ModelAndView hello(@RequestParam(value = "abc") String abc){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("helloworld");
        modelAndView.getModel().put("attr2",abc);
        return modelAndView;
    }

    @RequestMapping(value = "/hello2")
    public String hello2(){
        return "helloworld";
    }
}
